package com.xnyzc.lhy.common.util.validation;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * 正则效验
 *
 * @author zhaolijie
 * @date
 */
public class RegularValidation {

    // 手机号正则
    private static final Pattern phone = Pattern.compile("^((13[0-9])|(14[^3])|(15[^4])|(16[2,5,6,7])|(17[0-9])|(18[0-9])|(19[^4]))\\d{8}$");
    // 姓名正则
    private static final Pattern name = Pattern.compile("^([\\u4e00-\\u9fa5]{1,20}|[a-zA-Z\\.\\s]{1,20})$");
    // 身份证号正则
    private static final Pattern idCard = Pattern.compile("(^[1-9]\\d{5}(18|19|([23]\\d))\\d{2}((0[1-9])|(10|11|12))(([0-2][1-9])|10|20|30|31)\\d{3}[0-9Xx]$)|(^[1-9]\\d{5}\\d{2}((0[1-9])|(10|11|12))(([0-2][1-9])|10|20|30|31)\\d{2}[0-9Xx]$)");
    // 正整数（包括0）
    private static final Pattern positiveIntegerZero = Pattern.compile("^\\d+$");
    // 正整数（不包括0）
    private static final Pattern positiveIntegerNoZero = Pattern.compile("^[0-9]*[1-9][0-9]*$");
    // 车牌号(新能源)
    private static final Pattern newVehNo = Pattern.compile("^[京津沪渝冀豫云辽黑湘皖鲁新苏浙赣鄂桂甘晋蒙陕吉闽贵粤青藏川宁琼使领]{1}[A-Z]{1}(([0-9]{5}[DF]$)|([A-Z][A-HJ-NP-Z0-9][0-9]{4}$))");
    // 车牌号(非新能源)
    private static final Pattern vehNo = Pattern.compile("^[京津沪渝冀豫云辽黑湘皖鲁新苏浙赣鄂桂甘晋蒙陕吉闽贵粤青藏川宁琼使领A]{1}[A-Z]{1}[A-HJ-NP-Z0-9]{4}[A-HJ-NP-Z0-9挂学警港澳]{1}$");

    public static final String CASE_PHONE = "phone";
    public static final String CASE_NAME = "name";
    public static final String CASE_ID_CARD = "idCard";
    public static final String CASE_POSITIVE_INTEGERZERO = "positiveIntegerZero";
    public static final String CASE_POSITIVE_INTEGER_NO_ZERO = "positiveIntegerNoZero";
    public static final String CASE_NEWVEHNO = "newVehNo";
    public static final String CASE_VEHNO = "vehNo";

    /**
     * @param type：类型
     * @param value：需要效验的数据
     * @return
     */
    public static Boolean validationData(String type, String value) {
        switch (type) {
            case CASE_PHONE: {
                Matcher matcher = phone.matcher(value);
                return matcher.matches();
            }
            case CASE_NAME: {
                Matcher matcher = name.matcher(value);
                return matcher.matches();
            }
            case CASE_ID_CARD: {
                Matcher matcher = idCard.matcher(value);
                return matcher.matches();
            }
            case CASE_POSITIVE_INTEGERZERO: {
                Matcher matcher = positiveIntegerZero.matcher(value);
                return matcher.matches();
            }
            case CASE_POSITIVE_INTEGER_NO_ZERO: {
                Matcher matcher = positiveIntegerNoZero.matcher(value);
                return matcher.matches();
            }
            case CASE_NEWVEHNO: {
                Matcher matcher = newVehNo.matcher(value);
                return matcher.matches();
            }
            case CASE_VEHNO: {
                Matcher matcher = vehNo.matcher(value);
                return matcher.matches();
            }
            default: {
                return false;
            }
        }
    }

}
